package com.neusoft.neuiotms.dcom.converter.change;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.change.ChangeRegistrationAttachmentDTO;
import com.neusoft.neuiotms.dcom.model.change.ChangeRegistrationAttachment;
import com.neusoft.neuiotms.dcom.repository.change.ChangeRegistrationAttachmentRepository;

@Component
public class ChangeRegistrationAttachmentConverter
        extends AbstractConverter<ChangeRegistrationAttachment, ChangeRegistrationAttachmentDTO> {

    @Autowired
    private ChangeRegistrationAttachmentRepository changeRegistrationAttachmentRepository;

    @Override
    public ChangeRegistrationAttachment toModel(final ChangeRegistrationAttachmentDTO dto) {
        ChangeRegistrationAttachment model;
        if (dto.isNew()) {
            model = new ChangeRegistrationAttachment();
        } else {
            model = this.changeRegistrationAttachmentRepository.getOne(dto.getId());
        }
        model.setFsId(dto.getFsId());
        model.setName(dto.getName());
        return model;
    }

    @Override
    public ChangeRegistrationAttachmentDTO toDTO(final ChangeRegistrationAttachment model,
            final boolean forListView) {
        final ChangeRegistrationAttachmentDTO dto = new ChangeRegistrationAttachmentDTO();
        dto.setFsId(model.getFsId());
        dto.setId(model.getId());
        dto.setName(model.getName());
        return dto;
    }

}
